<!--用户行为漏斗分析-->
<template>
    <el-row :gutter="24" class="el-row">
      <el-col :span="24" class="el-card">
      <div id="userConversionChart" style="width:100%;height:500px;" />
      </el-col>
    </el-row>
</template>


<script>
import * as echarts from 'echarts'
import api from '@/api/statistics/user/user'
export default {

  // 生命周期函数：内存准备完毕，页面尚未渲染
  created() {
    console.log('list created......')
    // this.init()
  },

  // 生命周期函数：内存准备完毕，页面渲染成功
  mounted() {
    this.init()
  },

  data () {
    return {
      xData:[ ],
      yData:[],
      searchObj: {
        recentDays: this.$parent.recentDays,
        dt: this.$parent.curDate
      }
    }
  },
  methods: {
    init() {
      this.searchObj.recentDays = this.$parent.recentDays
      this.searchObj.dt = this.$parent.curDate
      api.getUserActionConvert(this.searchObj).then(response => {
        this.xData = response.data.xdata
        this.yData = response.data.ydata

        this.setChartData()
      }).catch( response => {
          console.log('失败'+response)
        })
    },

    setChartData() {
    const option = {
    title: {
        text: '用户行为漏斗分析',
        subtext: this.$parent.dateRange
    },
    tooltip: {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c}%"
    },
    toolbox: {
        feature: {
            dataView: {readOnly: false},
            restore: {},
            saveAsImage: {}
        }
    },
    legend: {
        data: this.xData
    },

    series: [
        {
            name:'漏斗图',
            type:'funnel',
            left: '10%',
            top: 60,
            //x2: 80,
            bottom: 60,
            width: '80%',
            // height: {totalHeight} - y - y2,
            min: 0,
            max: 100,
            minSize: '0%',
            maxSize: '100%',
            sort: 'descending',
            gap: 2,
            label: {
                show: true,
                position: 'inside'
            },
            labelLine: {
                length: 10,
                lineStyle: {
                    width: 1,
                    type: 'solid'
                }
            },
            itemStyle: {
                borderColor: '#fff',
                borderWidth: 1
            },
            emphasis: {
                label: {
                    fontSize: 20
                }
            },
            data: this.yData
        }
    ]
};
      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(document.getElementById('userConversionChart'))
      myChart.clear()
      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option)
    }
  }
}
</script>

